<template>
  <div>
    <div><h1>订单列表</h1></div>
    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="orderId" label="订单ID" width="100" />
        <el-table-column prop="orderNo" label="订单编号" width="200" />
        <el-table-column prop="orderStatus" label="订单状态" width="100">
          <template #default="scope">
            <el-tag v-if="scope.row.orderStatus === 0">未支付</el-tag>
            <el-tag v-if="scope.row.orderStatus === 1">已支付</el-tag>
            <el-tag v-if="scope.row.orderStatus === 2">待发货</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="orderAmount" label="订单金额" width="100" />
        <el-table-column prop="payTime" label="支付时间" width="160" />
        <el-table-column prop="orderType" label="订单类型" width="100" />
        <el-table-column prop="userId" label="用户ID" width="100" />
        <el-table-column prop="prodInfo" label="商品信息" width="260" />
        <el-table-column prop="createBy" label="创建人" width="100" />
        <el-table-column prop="createTime" label="创建时间" width="160" />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button
              type="primary"
              size="small"
              @click="handleEdit(scope.row)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              @click="handleDelete(scope.row)"
              size="small"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="margin-top: 20px">
      <el-pagination
        v-model:current-page="pageInfoVo.pageNum"
        v-model:page-size="pageInfoVo.pageSize"
        :page-sizes="[2, 4, 6, 8]"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getPageListOrder } from "@/api/api";
//列表数据
const tableData = ref([]);
//分页条数
const total = ref(0);
//查询条件
const pageInfoVo = ref({
  pageNum: 1,
  pageSize: 4,
});
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  pageInfoVo.value.pageSize = val;
  loadOrderList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  pageInfoVo.value.pageNum = val;
  loadOrderList();
};
const loadOrderList = () => {
  getPageListOrder(pageInfoVo.value).then((res) => {
    tableData.value = res.data.data.records;
    total.value = res.data.data.total;
  });
};
onMounted(() => {
  loadOrderList();
});
</script>

<style scoped></style>
